-
Notifications
You must be signed in to change notification settings - Fork 0
feat(perf): cache images and assets, serve and normalise image variants #96
Merged
+1,162
−64
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Only the title link opened a recipe; clicking the image did nothing. Wrap the image in a link to the same page that is hidden from assistive technology and the tab order, so keyboard and screen-reader users still get a single link per card. Both links keep the browse state for Back. Closes #82
- Images: replace Cache-Control no-store with no-cache plus a strong ETag (public/private by recipe visibility). The access check still runs on every request, so privacy changes apply immediately, but unchanged images are answered with an empty 304 instead of being re-downloaded. - Thumbnails: the API generates 480/800 px WebP variants (?w=) with sharp on first request and caches them under UPLOAD_DIR/variants; cleanup removes them with the original. Recipe cards use srcset/sizes. A seed image goes from 133.6 KB to 18.2 KB at 480 px. - Apache: immutable one-year caching for hashed /assets, no-cache for index.html (deploy/apache.conf, needs mod_headers on the VM). - Fallback image resized to 800 px: 173.4 KB -> 51.2 KB. - GraphQL responses keep no-store. Closes #70
Following team review of #70: - Every upload is processed with sharp on the server, whatever the client sent: EXIF auto-rotation, at most 1600 px on the longest side, WebP quality 80, metadata (e.g. GPS) dropped. Quotas use the stored size. Existing files and URLs are unchanged. - Card variants (480/800 px) are built at upload time; older images still get them lazily. The recipe detail image now uses srcset/sizes too. - The global storage limit counts variant files. Variants already go through the same authorization (incl. privacy changes) and cleanup. Refs #70
olestan
requested changes
Nov 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The caching and image processing changes introduce a few regression risks worth addressing before merging:
- Stale images (
imageStore.ts:151–156): Re-seeding overwrites images with stable filenames, but cached variants and ETags remain unchanged. This can cause browsers to display outdated images. Invalidate variants and update ETags when originals change. - EXIF orientation (
imageStore.ts:158–161): Variants generated from older JPEGs don't apply auto-rotation, potentially displaying images sideways. Add.rotate()and a regression test. - Orphaned variants (
imageStore.ts:273–298): Cleanup doesn't remove variants when their original files are already missing. These files continue consuming quota and can eventually block uploads.
I'd recommend addressing these cases, particularly cache invalidation and storage accounting, before merging.
Review on #90 was right: the title link's ::after overlay already covers the whole card, so clicking the image already opened the recipe (checked in a real browser). The extra aria-hidden image link was redundant and hid the image alt text from screen readers. Restore RecipeCard as before and add a browser test that clicks the image centre, since jsdom cannot hit-test the CSS overlay. Closes #82
…et-caching # Conflicts: # apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx
Review on #96: - ETags include the original's size and mtime, and cached variants are rebuilt when the original is newer, so re-seeded images (same filenames) are never shown stale. - Variants apply EXIF auto-rotation, so older JPEG uploads stored before server-side normalisation are not shown sideways. - Cleanup removes variants (and interrupted .tmp writes) whose original no longer exists, so they stop counting against the storage limit. Refs #70
|
Thanks — all three were real. Fixed in the latest commit:
Also merged the updated #90 (the card image link is gone there), so this PR now only adds |
olestan
approved these changes
Nov 16, 2026
5 tasks
oliveror
added a commit
that referenced
this pull request
Nov 17, 2026
…os (#118) * test(e2e): split the integrated browser test into independent scenarios The real-API browser test was one 90-second journey, so an early failure hid everything after it. It is now six independent scenarios (image upload and removal, editing, rating, saving to the cookbook, privacy and deletion) plus one short end-to-end journey through the real registration and publishing UI. Scenario users are created through the auth service with a real session cookie, because UI registration is rate limited to 5 per minute per IP, and recipes through the repository. Closes #108 * test(e2e): restore image, rating-then-save and search regression checks - The edit scenario now edits a recipe that has an uploaded image and checks the same image is still shown, loaded, after reload. - The rating scenario saves to My Cookbook straight after changing the rating, and unsaves/saves straight after removing it; after reload the recipe is saved and unrated. - The journey first searches an unrelated term and waits for the empty result (so a loading state cannot pass the check), then finds the recipe by title. Verified that ignoring the search term on the server, or dropping the image on save, makes the scenarios fail. * test(e2e): use a realistically sized image in the edit scenario The recipe page now serves images with srcset width descriptors (#96), and the browser scales naturalWidth by the chosen density, so the 1x1 test PNG reported 0 although it loaded. The scenario now uploads a 600x400 PNG, and calls upload() without the extension argument #96 removed. * test(e2e): check another user saves the edited recipe; poll image load Restores the original journey's check that another user can save an edited recipe and sees its new title in My Cookbook, in the edit scenario. The upload scenario now polls naturalWidth, as the image can be visible before it has finished loading. Refs #108
Sign in
to join this conversation on GitHub.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
HTTP caching
Cache-Control/project2/assets/*public, max-age=31536000, immutable(Apache,deploy/apache.conf)index.htmland other client filesno-cache/uploads/…)public, no-cache+ strongETagprivate, no-cache+ strongETagno-store(unchanged)Upload filenames are UUIDs and never overwritten, so the filename is a safe ETag. The access check still runs on every request, including revalidations, so an image stops showing as soon as its recipe becomes private, while unchanged images are answered with an empty
304instead of being re-downloaded (previouslyno-storere-sent every image on every visit).Server-side image processing (added after team review)
sharpon the server, whatever the client sent: EXIF auto-rotation, at most 1600 px on the longest side, WebP quality 80. Metadata such as GPS position is not copied (privacy). Quotas count the stored size. Existing files and URLs are unchanged.UPLOAD_DIR/variants/. Recipe cards and the recipe detail image usesrcset/sizes. A seed image goes from 133.6 KB to 18.2 KB at 480 px.authorize()check as the original (so privacy changes apply), cleanup removes variants with the original, and the global storage limit now counts variant files.Other
sharp0.34.4 is a new API dependency; the lockfile includes the prebuilt Linux x64 binary used on the deploy runner.Validation
npm run checkpasses (220 unit tests), incl. new tests for cache headers, 304 revalidation, revalidation after a recipe becomes private, variant widths.test:api(16) against PostgreSQL 16, extended to cover:public/private, no-cache, 304 withIf-None-Match, 404 for a stale ETag after the recipe turns private, real variant generation on disk, variant removal by cleanup, and a 3000×2000 JPEG stored as a 1600×1067 WebP.deploy/apache.conftested in a real Apache 2.4 container: assets getimmutable,index.html/ SPA routes / favicon getno-cache.Remaining work (VM)
sudo a2enmod headers, applydeploy/apache.conf, reload Apache. Deploys do not install the Apache config.npm ci --omit=devinstallssharpon the runner (lockfile contains@img/sharp-linux-x64; not testable from here).AI usage
Written with Claude Code (Anthropic) during the final-delivery review and extended after a teammate's review. Please review the diff as you would any other contribution.
Closes #70